/*
 * SHA1.h
 *
 *  Created on: Jul 19, 2012
 *      Author: hooyao
 */

#ifndef SHA1_H_
#define SHA1_H_

#define h0	0x67452301
#define h1  0xEFCDAB89
#define h2  0x98BADCFE
#define h3 	0x10325476
#define h4 	0xC3D2E1F0
#define BLK_LEN 64 	//bytes,512bits
#define LEN_LEN 8	//bytes,64bits
//TODO define LONG and INT to suit 32bit and 64bit environment

class SHA1 {
private:
	unsigned char* m_msg;
	unsigned long m_msglength;
	unsigned char* m_residual;
	unsigned char* m_lenData;
	unsigned char* digest;

public:
	void update(unsigned char* message, unsigned long len);
	void dofinal();
	inline unsigned int RotateLeft(unsigned int n, unsigned int i) {
		return (n << i) | (n >> (32 - i));
	}

	inline unsigned int RotateRight(unsigned int n, unsigned int i) {
		return (n >> i) | (n << (32 - i));
	}
	inline 	unsigned char* getDigest(){
		return this->digest;
	}
};

#endif /* SHA1_H_ */
